<script setup lang="ts">
import { ref, defineEmits } from "vue";
import { addHost } from "@/api/vap/cluster";

const emit = defineEmits(["onSearchEnv"]);
const onSearchTable = () => {
  emit("onSearchEnv");
};
const formArgus = ref({
  hostName: "",
  ip: "",
  mac: "",
  domain: "",
  systemInfo: "",
  osType: 1,
  buildNumber: "",
  version: "",
  guaIp: "",
  guaPort: 3389,
  guaProtocol: "rdp",
  origin: 1,
  status: 1,
  username: "",
  password: ""
});

const dialogVisible = ref(false);

const showdialogForAdd = () => {
  formArgus.value = {
    hostName: "",
    ip: "",
    mac: "",
    domain: "",
    systemInfo: "",
    osType: 1,
    buildNumber: "",
    version: "",
    guaIp: "",
    guaPort: 3389,
    guaProtocol: "rdp",
    origin: 1,
    status: 1,
    username: "",
    password: ""
  };
  dialogVisible.value = true;
};

const clickSubmit = () => {
  addHost(formArgus.value).then(() => {
    dialogVisible.value = false;
    onSearchTable();
  });
};
defineExpose({
  showdialogForAdd
});
</script>

<template>
  <el-dialog v-model="dialogVisible" title="手动添加主机">
    <el-form ref="elForm" :model="formArgus" label-width="100px">
      <el-form-item label="主机名称">
        <el-input
          v-model="formArgus.hostName"
          placeholder="请输入主机名称"
          :maxlength="50"
          show-word-limit
          clearable
        />
      </el-form-item>
      <el-form-item label="主机IP">
        <el-input
          v-model="formArgus.ip"
          placeholder="请输入主机IP"
          :maxlength="50"
          show-word-limit
          clearable
        />
      </el-form-item>
      <el-form-item label="mac地址">
        <el-input
          v-model="formArgus.mac"
          :maxlength="50"
          show-word-limit
          clearable
        />
      </el-form-item>
      <el-form-item label="域">
        <el-input
          v-model="formArgus.domain"
          :maxlength="50"
          show-word-limit
          clearable
        />
      </el-form-item>
      <el-form-item label="系统信息">
        <el-input
          v-model="formArgus.systemInfo"
          :maxlength="50"
          show-word-limit
          clearable
        />
      </el-form-item>
      <el-form-item label="系统类型">
        <el-radio-group v-model="formArgus.osType">
          <el-radio :label="1">windows</el-radio>
          <el-radio :label="2">linux</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="GUAIP">
        <el-input
          v-model="formArgus.guaIp"
          :maxlength="50"
          show-word-limit
          clearable
        />
      </el-form-item>
      <el-form-item label="GUA PORT">
        <el-input
          v-model="formArgus.guaPort"
          :maxlength="50"
          show-word-limit
          clearable
        />
      </el-form-item>
      <el-form-item label="GUA 协议">
        <el-input
          v-model="formArgus.guaProtocol"
          :maxlength="50"
          show-word-limit
          clearable
        />
      </el-form-item>
      <el-form-item label="账户">
        <el-input
          v-model="formArgus.username"
          :maxlength="50"
          show-word-limit
          clearable
        />
      </el-form-item>
      <el-form-item label="密码">
        <el-input
          v-model="formArgus.password"
          :maxlength="50"
          show-word-limit
          clearable
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="clickSubmit"> 提交 </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style scoped></style>
